//
//  CMDBResultPeopleTableView.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/28.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let resultPeopleCellID = "resultPeopleCellID"

class CMDBResultPeopleTableView: CMDBBaseTableView {
    
    var loadData : Bool = false
    
    
    override func setupTableView() {
        super.setupTableView()
        
        registerClass(CMDBResultPeopleCell.self, forCellReuseIdentifier: resultPeopleCellID)
   
        let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.25 * Double(NSEC_PER_SEC)))
        dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in
            var indexPaths = [NSIndexPath]()
            for i in 0 ..< 10 {
                indexPaths.append(NSIndexPath(forRow: i, inSection: 0))
            }
            
            self.loadData = true
            
            self.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Left)
        }
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return loadData ? 10 : 0
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
        
        let cell = dequeueReusableCellWithIdentifier(resultPeopleCellID) as! CMDBResultPeopleCell
        
        return cell
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        return 80
    }
    
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        
        mDelegate?.onItemClickType!("TableViewCellClick", data:nil, indexPath: indexPath)
    }
    
    
}
